﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PServiceBus.Core.Interface;
using PServiceBus.Core.Runtime.Configuration;

namespace PServiceBus.Core.Runtime {
    public class KeyValueStore {
        /// <summary>
        /// Return current KeyValueStore that implements IKeyValueStore
        /// </summary>
        public static IKeyValueStore Instance {
            get {
                var obj = PServiceBus.Core.Runtime.ServiceLocator<IKeyValueStore>.Get();
                if (obj == null) {
                    var keyValueStoreType = ConfigurationProvider.KeyValueStoreType;
                    obj = Activator.CreateInstance(keyValueStoreType) as IKeyValueStore;
                    PServiceBus.Core.Runtime.ServiceLocator<IKeyValueStore>.Set(obj);
                }
                return obj;
            }
        }
    }
}
